#!/bin/sh -
## set_projet.sh for  in /home/osirven/devel/baseZF
##
## Made by Olivier
## Login   <hthetiot@japanim.fr>
##
## Started on  Thu Oct 12 18:13:37 2006 Olivier
## Last update Tue Oct 24 12:18:05 2006 Olivier
##
##
## $Id: set_projet.sh 2 2006-10-24 10:18:56Z osirven $
## @author $Author: osirven $
## @version $Revision: 2 $
## @filesource
## @package
##

BASEROOT=`pwd | sed s@/tools@@g`
BASEDIRNAME=`basename $BASEROOT`
BASEMAINCLASS=Basezf
BASEMAINCLASS_LC=`echo $BASEMAINCLASS | awk '{print tolower($0);}'`
BASEMAINCLASS_UC=`echo $BASEMAINCLASS | awk '{print toupper($0);}'`

read -e -p "please enter the name of your project: " PROJECT

MAINCLASS=`echo $PROJECT | awk '{printf("%s%s\n", toupper(substr($0, 1, 1)), tolower(substr($0, 2)));}'`

read -e -p "please enter the name of your main class [$MAINCLASS]: " USERCLASS
if [ -n "$USERCLASS" ]; then
    MAINCLASS=$USERCLASS
fi

MAINCLASS_LC=`echo $MAINCLASS | awk '{print tolower($0);}'`
MAINCLASS_UC=`echo $MAINCLASS | awk '{print toupper($0);}'`

echo "setting up project..."

for file in `rgrep -l $BASEDIRNAME *`; do
    cat $file | sed s/$BASEDIRNAME/$PROJECT/g > $file.new && mv -f $file.new $file
done
for file in `rgrep -l $BASEMAINCLASS *`; do
    cat $file | sed s/$BASEMAINCLASS/$MAINCLASS/g > $file.new && mv -f $file.new $file
done
for file in `rgrep -l $BASEMAINCLASS_LC *`; do
    cat $file | sed s/$BASEMAINCLASS_LC/$MAINCLASS_LC/g > $file.new && mv -f $file.new $file
done
for file in `rgrep -l $BASEMAINCLASS_UC *`; do
    cat $file | sed s/$BASEMAINCLASS_UC/$MAINCLASS_UC/g > $file.new && mv -f $file.new $file
done

for file in `find -name "$BASEMAINCLASS*"`; do
    newfile=`echo $file | sed s/$BASEMAINCLASS/$MAINCLASS/g`
    mv $file $newfile
done
for file in `find -name "$BASEMAINCLASS_LC*"`; do
    newfile=`echo $file | sed s/$BASEMAINCLASS_LC/$MAINCLASS_LC/g`
    mv $file $newfile
done
for file in `find -name "$BASEMAINCLASS_UC*"`; do
    newfile=`echo $file | sed s/$BASEMAINCLASS_UC/$MAINCLASS_UC/g`
    mv $file $newfile
done

if [ $BASEDIRNAME != $PROJECT ]; then
    cd .. && mv $BASEDIRNAME $PROJECT && cd $PROJECT
fi

find -type d -name '.svn' -exec rm -rf {} \; 2> /dev/null

echo "done"